<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日志列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/oksub.css">
</head>
<body>
<div class="ok-body">
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input class="layui-input" placeholder="开始日期" autocomplete="off" id="startTime" name="startTime">
            <input class="layui-input" placeholder="截止日期" autocomplete="off" id="endTime" name="endTime">
            <input class="layui-input" placeholder="选择操作员" autocomplete="off" name="operator">
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
    layui.use(["element", "table", "form", "laydate", "okLayer", "okUtils", "okMock","okCookie"], function () {
        let $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;
        var util = layui.util;
        var laydate = layui.laydate;
        var okLayer = layui.okLayer;
        var okUtils = layui.okUtils;
        var okMock = layui.okMock;

        util.fixbar({});
        laydate.render({elem: "#startTime", type: "datetime"});
        laydate.render({elem: "#endTime", type: "datetime"});

        var articleTable = table.render({
            elem: "#tableId",
            url: okMock.api.logger.list,
            method: "POST",
            limits: [10, 15, 20, 30],
            limit: 10,
            page: true,
            even: true,
            contentType: "application/json;charset=utf-8",
            headers: {
                token: okUtils.token,
            },
            request: {
                pageName: "pageNum",
                limitName: "pageSize"
            },
            parseData(res) {//格式化数据
                return {
                    "code": res.code,
                    "message": res.message,
                    "count": res.data.result.total,
                    "data": res.data.result.items
                }
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code, statusCode: 200 //成功的状态码，默认：0
                statusCode: 20000,//设置成功状态码为20000
                msgName: 'message', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: "id", title: "编号", width: 280, sort: true},
                {field: "operator", title: "操作员", width: 150},
                {field: "operation", title: "操作描述", width: 250, templet: "#urlTpl"},
                {field: "spendTime", title: "请求耗时", width: 100},
                {field: "ip", title: "IP地址", width: 180},
                {field: "method", title: "请求方法类型", width: 100, align: "center", templet: "#topTpl"},
                {field: "ip", title: "请求URI", width: 180},
                {field: "createTime", title: "创建时间", align: "center", templet: "#statusTpl"}
            ]],
            done: function (res, curr, count) {//执行后操作
                console.log(res, curr, count)
            }
        });
        form.on("submit(search)", function (data) {
            articleTable.reload({
                where: {
                    startTime: data.field.startTime,
                    endTime: data.field.endTime,
                    operator: data.field.operator,
                    // pipeLogQuery: data.field,
                },
                contentType: "application/json;charset=utf-8",
                method: 'POST',
                headers: {
                    token: okUtils.token,
                },
                page: {curr: 1},
                // parseData(res) {//格式化数据
                //     return {
                //         "code": res.code,
                //         "message": res.message,
                //         "count": res.data.result.total,
                //         "data": res.data.result.items
                //     }
                // },
                // response: {
                //     statusName: 'code', //数据状态的字段名称，默认：code, statusCode: 200 //成功的状态码，默认：0
                //     statusCode: 20000,//设置成功状态码为20000
                //     msgName: 'message', //状态信息的字段名称，默认：msg
                //     countName: 'count', //数据总数的字段名称，默认：count
                //     dataName: 'data' //数据列表的字段名称，默认：data
                // },
            });
            return false;
        });
    })
</script>
<!-- 头工具栏模板 -->
<!--        <script type="text/html" id="toolbarTpl">-->
<!--            <div class="layui-btn-container">-->
<!--                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchEnabled">批量上架</button>-->
<!--                <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="batchDisabled">批量下架</button>-->
<!--                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">批量删除</button>-->
<!--                <button class="layui-btn layui-btn-sm" lay-event="add">添加文章</button>-->
<!--            </div>-->
<!--        </script>-->
<!-- 链接模板 -->
<!--        <script type="text/html" id="urlTpl">-->
<!--            <a href="{{d.url}}" target="_blank">{{d.url}}</a>-->
<!--        </script>-->
<!-- 是否指顶模板
    <input type="checkbox" name="isTop" value="{{d.isTop}}" lay-skin="switch" lay-text="是|否" {{ d.isTop== true ? 'checked' : ''}}>
-->
<!--        <script type="text/html" id="topTpl">-->
<!--            {{#  if(d.isTop == true){ }}-->
<!--            <span class="layui-btn layui-btn-normal layui-btn-xs">已置顶</span>-->
<!--            {{#  } else if(d.isTop == false) { }}-->
<!--            <span class="layui-btn layui-btn-warm layui-btn-xs">未置顶</span>-->
<!--            {{#  } }}-->
<!--        </script>-->
<!-- 发布状态模板
    <input type="checkbox" name="top" value="{{d.status}}" lay-skin="switch" lay-text="已发布|未发布" {{ d.status== true ? 'checked' : ''}}>
-->
<!--<script type="text/html" id="statusTpl">-->
<!--    {{#  if(d.status == true){ }}-->
<!--    <span class="layui-btn layui-btn-normal layui-btn-xs">已发布</span>-->
<!--    {{#  } else if(d.status == false) { }}-->
<!--    <span class="layui-btn layui-btn-warm layui-btn-xs">未发布</span>-->
<!--    {{#  } }}-->
<!--</script>-->
<!-- 行工具栏模板 -->
<!--        <script type="text/html" id="operationTpl">-->
<!--            <a href="javascript:" title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>-->
<!--            <a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>-->
<!--        </script>-->
</body>
</html>
